<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('Plannew/index')}">列表</a></li>
        <li class="active"><a href="{:url('Plannew/add')}">添加</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('Plannew/addPost')}">
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 计划类型:</label>
            <div class="col-md-6 col-sm-10">
                <select name="type" class="form-control" id="type" onchange="selecttype()">
                    <option value=0>请选择</option>
                    <volist name="type_id_arr" id="ao">
                        <option
                        <if isset($vo.type)&&$vo.type==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.name}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 计划号:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" readonly type="text" class="form-control" id="name" name="name" value="{$vo.name|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 用途类型:</label>
            <div class="col-md-6 col-sm-10">
                <select name="c_type" class=" form-control selectpicker" data-live-search="true">
                    <volist name="c_type_arr" id="ao">
                        <option
                        <if isset($vo.c_type)&&$vo.c_type==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.name}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 归属类型:</label>
            <div class="col-md-6 col-sm-10">
                <select name="companytype" class="form-control">
                    <volist name="companytypea_arr" id="ao">
                        <option
                        <if isset($vo.companytype)&&$vo.companytype==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.name}</option>
                    </volist>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 合同编号:</label>
            <div class="col-md-6 col-sm-10">
                <select name="ht_id" class=" form-control selectpicker" data-live-search="true" onchange="htchange()" id="ht_id">
                    <option value=0>请选择</option>
                    <volist name="ht_id_arr" id="ao">
                        <option
                        <if isset($vo.ht_id)&&$vo.ht_id==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.ht_number}</option>
                    </volist>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 客户名称:</label>
            <div class="col-md-6 col-sm-10">
                <select name="company_id" class=" form-control selectpicker" data-live-search="true" id="company_id">
                    <option value=0>请选择</option>
                    <volist name="company_id_arr" id="ao">
                        <option
                        <if isset($vo.company_id)&&$vo.company_id==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.name}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 牌号:</label>
            <div class="col-md-6 col-sm-10">
                <select name="grade_id" class=" form-control selectpicker" data-live-search="true" id="grade_id" onchange="getsteelgrade()">
                    <option value=0>请选择</option>
                    <volist name="grade_id_arr" id="ao">
                        <option
                        <if isset($vo.grade_id)&&$vo.grade_id==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.g_name}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 钢种:</label>
            <div class="col-md-6 col-sm-10">
                <select name="steel_grade_id" class=" form-control selectpicker" data-live-search="true" id="steel_grade_id" onchange="getcoil()">
                    <option value=0>请选择</option>
                    <volist name="steel_grade_id_arr" id="ao">
                        <option
                        <if isset($vo.steel_grade_id)&&$vo.steel_grade_id==$ao.id>selected</if>
                        value="{$ao.id}">{$ao.name}</option>
                    </volist>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 交付时间:</label>
            <div class="col-md-6 col-sm-10">
                <input autocomplete="off" type="text" class="form-control js-datetime" id="delivery_time"
                       name="delivery_time"
                       value="{$now_time|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 生产日期:</label>
            <div class="col-md-6 col-sm-10">
                <input autocomplete="off" type="text" class="form-control js-datetime" name="pd"
                       value="{$now_time|default=''}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 钢板信息:</label>
            <div class="col-md-6 col-sm-10">
                <select name="plate_id[]"  id="plate_id" class="multiselect form-control selectpicker " multiple="multiple"data-live-search="true" onchange="getplate()">
                    <volist name="plate_id_arr" id="ao" >
                        <option
                        <if isset($vo.plate_id)&&in_array($ao.id,$vo.plate_id)>selected</if>
                        value="{$ao.id}">{$ao.name}-
                        {$type[$ao.type]|default=''}-
                        {$steel_grade_arr_da[$ao.steel_id]|default=''}-
                        {$grade_id_arr_all[$ao.grade_id]|default=''}
                        -{$coil_id_arr_all[$ao.coil_id]|default=''}-
                        {$ao.d}*{$ao.w}*{$ao.h}-
                        {$ao.sheets}张

                        </option>
                    </volist>
                </select>
            </div>

        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 厚:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" id="d" name="d" value="{$vo.d|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 宽:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" id="w" name="w" value="{$vo.w|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 长:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" id="h" name="h" value="{$vo.h|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 张数:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" id="sheets" name="sheets"
                       value="{$vo.sheets|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 图片附件:</label>
            <div class="col-md-6 col-sm-10">
                <input readonly  style="display: inline-block;width:80%;" class="form-control" name="image_enclosure"
                       id="image_enclosure"
                       type="text"
                       title="图片名称" value="">
                <a class="btn btn-success"
                   href="javascript:uploadMultiFile('图片上传','#image_enclosureCnt','#image_enclosure','image');">上传</a>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span> 预览</label>
            <div id="image_enclosureCnt" class="col-md-6 col-sm-10">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 文件附件:</label>
            <div class="col-md-6 col-sm-10">
                <input readonly style="display: inline-block;width:80%;" class="form-control" name="file_enclosure"
                       id="file_enclosure"
                       type="text"
                       title="图片名称" value="">
                <a class="btn btn-success"
                   href="javascript:uploadMultiFile('文件上传','file_enclosureCnt','file_enclosure','file');">上传</a>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span> 预览</label>
            <div id="file_enclosureCnt" class="col-md-6 col-sm-10">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required"></span> 备注:</label>
            <div class="col-md-6 col-sm-10">
                <input placeholder="" type="text" class="form-control" name="remrk" value="{$vo.remrk|default=''}">
            </div>
        </div>
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-primary js-ajax-submit">保存</button>
            <a class="btn btn-default" href="{:url('Plannew/index')}">返回</a>
        </div>
    </form>

</div>
<script src="/static/js/admin.js"></script>
<script src="/static/js/layer/layer.js"></script>
<script type="text/javascript">
    var steel_grade_arr_da1 = new Array();
    steel_grade_arr_da1 = {$steel_grade_arr_da1};
    var plate_id_arrq = new Array();
    plate_id_arrq = {$plate_id_arrq};

    var grade_id_arr_all1 = new Array();
    grade_id_arr_all1 = {$grade_id_arr_all1};
    var coil_id_arr_all1 = new Array();
    coil_id_arr_all1 = {$coil_id_arr_all1};
    var type1 = new Array();
    type1 = {$type1};


    function selecttype(){
        var type = $('#type').val()
        // alert(type);
        if (type>1){
            $.ajax({
                type: "POST",
                url: "{:url('Plannew/getname')}",
                contentType: "application/json", //如果提交的是json数据类型，则必须有此参数,表示提交的数据类型
                // dataType: "json", //表示返回值类型，不必须
                data:type,
                success: function (res) {
                    // $("#plate_id").html("");
                    //在原来的页面跳转到下载word模板的页面
                    console.log(res)
                    if (res.code == 1 && res.data != '') {
                        $("#name").val(res.data);

                    }
                },
                error: function (data) {
                    alert("钢板接口请求失败，请联系管理员");
                }
            });
        }
    }

    function getplatenewd() {
        var arry = new Array();
        //循环所有选中的值
        $('input[name="coil_id[]"]:checked').each(function (index, element) {
            //追加到数组中
            arry.push($(this).val());
        });
        //将数组元素连接起来转化为字符串
        var arrystr = arry.join(',');
        console.log(arrystr)
        //输出到控制台
        if (arrystr != '') {
            $.ajax({
                type: "POST",
                url: "{:url('Plannew/findplate')}",
                contentType: "application/json", //如果提交的是json数据类型，则必须有此参数,表示提交的数据类型
                //dataType: "json", //表示返回值类型，不必须
                data: JSON.stringify(arrystr),
                success: function (res) {
                    $("#plate_id").html("");
                    //在原来的页面跳转到下载word模板的页面
                    console.log(res)
                    if (res.code == 1 && res.data != '') {
                        for (var i = 0; i < res.data.length; i++) {
                            // console.log(res.data[i])

                            $("#plate_id").append('  <label class="checkbox-inline"><input type="checkbox" name="plate_id[]" value="' + res.data[i]["id"] + '" id="id_' + i + '">&nbsp;<label for="id_' + i + '">' + res.data[i]["name"] + '-' + type1[res.data[i]["type"]]+ '-' + steel_grade_arr_da1[res.data[i]["steel_id"]]+ '-' + grade_id_arr_all1[res.data[i]["grade_id"]]+ '-' + coil_id_arr_all1[res.data[i]["coil_id"]]+ '-' + res.data[i]["d"]+ '*' + res.data[i]["w"]+ '*' + res.data[i]["h"]+ '-' + res.data[i]["sheets"] +'张'+'</label>&nbsp;&nbsp;</label>');



                        }
                    }
                },
                error: function (data) {
                    alert("钢板接口请求失败，请联系管理员");
                }
            });

        }else{
            $("#plate_id").html("");
        }
    }

    function htchange() {
        var ht_id = $('#ht_id').val()
        $.ajax({
            url: '{:url("Ht/findid")}?id=' + ht_id,
            type
    :
        'get',
            success(res)
        {
            console.log(res)
            // company_id: 1
            $('select[name=company_id]').find("option[value=" + res.data.company_id + "]").prop("selected", true);
            // delete_time: 0
            // delivery_time: 1657955400
            $('#delivery_time').val(res.data.delivery_time);
            // ht_d: "6.00"
            $('#d').val(res.data.ht_d);
            // ht_grade_id: "5"
            $('select[name=grade_id]').find("option[value=" + res.data.ht_grade_id + "]").prop("selected", true);
            $('select[name=companytype]').find("option[value=" + res.data.companytype + "]").prop("selected", true);
            // getsteelgrade(res.data.ht_grade_id);
            // ht_h: "1700.00"
            $('#h').val(res.data.ht_h);
            // ht_name: "测试001"
            // ht_number: "测试001"
            // ht_sheets: 7
            $('#sheets').val(res.data.ht_sheets);
            // ht_tw: "5768.00"
            // ht_w: "1800.00"
            $('#w').val(res.data.ht_w);
            // id: 6
            getsteelgrade()
        }
    })
    }

    function getsteelgrade() {


        var id = $('#grade_id').val()
        $.ajax({
            url: '{:url("Steelgrade/selctid")}?id=' + id,
            type
    :
        'get',
            success(res)
        {
            jQuery("#steel_grade_id").empty();

            if (res.code == 1 && res.data.length > 0) {
                jQuery("#steel_grade_id").prepend("<option value='0'>请选择</option>");   //为Select插入一个Option(第一个位置)

                for (var i = 0; i < res.data.length; i++) {
                    console.log(res.data[i])
                    jQuery("#steel_grade_id").append("<option value='" + res.data[i]['id'] + "'>" + res.data[i]['name'] + "</option>");
                }

            }

        }
    })
    }

    function getcoil() {


        var id = $('#steel_grade_id').val()
        $.ajax({
            url: '{:url("Plannew/selctid")}?id=' + id,
            type
    :
        'get',
            success(res)
        {
            $("#coil_id").html("");

            if (res.code == 1 && res.data.length > 0) {
                // jQuery("#coil_id").prepend("<option value='0'>请选择</option>");   //为Select插入一个Option(第一个位置)

                jQuery("#coil_id").prepend("<option value='0'>请选择</option>");   //为Select插入一个Option(第一个位置)

                for (var i = 0; i < res.data.length; i++) {
                    console.log(res.data[i])
                    jQuery("#coil_id").append("<option value='" + res.data[i]['id'] + "'>" + res.data[i]['name'] + "</option>");
                }


                // for (var i = 0; i < res.data.length; i++) {
                //     console.log(res.data[i])
                //     // jQuery("#coil_id").append("<option value='"+res.data[i]['id']+"'>"+res.data[i]['coilno']+"</option>");
                //     $("#coil_id").append('<input type="checkbox" onclick="getplatenewd(this)" name="coil_id[]" value="' + res.data[i]["id"] + '" id="id_' + i + '">&nbsp;<label for="id_' + i + '">' + res.data[i]["coilno"] + '-' + res.data[i]["product"] + '-' + steel_grade_arr_da1[res.data[i]["steel_grade_id"]] + '-' + res.data[i]["d"] + '*' + res.data[i]["w"] + '*' + res.data[i]["h"] +'-'+res.data[i]["weight"]+'吨'+ '</label>&nbsp;&nbsp;');
                //     //
                //     // <input type="checkbox" name="coil_id[]" value="4" id="id_1">&nbsp;<label for="id_1">R14550030101</label>&nbsp;&nbsp;
                // }

            }

        }
    })
    }
    function getplate(){
    var id = $('#plate_id').val()
    console.log(id)
    if (id) {
        oneid = id[0];
        // var id = $('#steel_grade_id').val()
        $.ajax({
            url: '{:url("Plannew/selctid")}?id=' + oneid,
            type: 'get',
            success(res) {
                console.log(res)
                $('#d').val(res.data[0].d);
                $('#w').val(res.data[0].w);
                $('#h').val(res.data[0].h);
            }
        })

    }
}
    //预览图片
    function bigSee(obj) {
        let src = $(obj).data('src');
        layer.open({
            title: '图片预览',
            area: ['50%', '100%'],
            content: `<iframe style="width:100%;height:100%;border:0;outline:0;" src="${src}"></iframe>`,
        });
    }

    /**
     * 删除图片
     * @param obj
     */
    function delImg(obj, idFlag = '#photo') {

        let oldPath = $(idFlag).val().trim();
        if (!oldPath) {
            return '';
        }

        let deleteRes = [$(obj).data('src')];
        oldPath = oldPath.split(',');
        oldPath = oldPath.filter(v => !deleteRes.some((item) => item === v))

        oldPath = oldPath.join(',');

        $(idFlag).val(oldPath);
        //删除原图片
        $(obj).parent().remove();
    }//预览
    function bigSee(obj) {
        let src = $(obj).data('src');
        layer.open({
            title: '文件预览',
            area: ['50%', '100%'],
            content: `<iframe style="width:100%;height:100%;border:0;outline:0;" src="${src}"></iframe>`,
        });
    }

    /**
     * 删除
     * @param obj
     */
    function delImg(obj, idFlag = '#photo') {

        let oldPath = $(idFlag).val().trim();
        if (!oldPath) {
            return '';
        }

        let deleteRes = [$(obj).data('src')];
        oldPath = oldPath.split(',');
        oldPath = oldPath.filter(v => !deleteRes.some((item) => item === v))

        oldPath = oldPath.join(',');

        $(idFlag).val(oldPath);
        //删除原图片
        $(obj).parent().remove();
    }
</script>
</body>
</html>